<?php
declare(strict_types=1);

namespace App\Controller\v1;

use App\Annotation\SystemLog;
use App\Controller\AbstractController;
use App\Request\Web\LoginRequest;
use App\Request\Web\RegisterRequest;
use App\Request\Web\RefreshTokenRequest;
use App\Service\Web\UsersService;
use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\PostMapping;
use Hyperf\Resource\Json\JsonResource;
#[Controller(prefix: '/api/web/v1')]
class AuthController extends AbstractController
{
    #[Inject]
    private UsersService $userService;
    #[PostMapping('auth/register')]
    public function register(RegisterRequest $request)
    {
        $data = $request->validated();

        $result = $this->userService->register($data);

        return new JsonResource($result);
    }
    #[PostMapping('auth/login')]
    #[SystemLog("用户登录", true, true)]
    public function login(LoginRequest $request)
    {
        $data = $request->validated();

        $result = $this->userService->login($data);

        return new JsonResource($result);
    }
}